package com.yulongtian.expression;

import com.yulongtian.domain.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自己实现的权限认证方法
 * @author yulongTian
 * @create 2022-10-30 22:02
 */
@Component("ex")
public class TylExpressionRoot {


    public Boolean hasAuthority(String authority) {
        //获取当前用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        List<String> permission = loginUser.getPermission();

        //判断用户权限集合中是否存在authority
        return permission.contains(authority);

    }

}
